﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;

namespace MyProblem
{
    public class QuestionOfArray
    {
        public int FindLengthOfLCIS(int[] nums)
        {
            if (nums.Length == 1 || nums.Length == 0)
                return nums.Length;
            int cis = 1;
            int tempCis = 1;
            for(int i = 0; i < nums.Length - 1; i++)
            {
                if(nums[i] < nums[i + 1])
                {
                    tempCis++;
                }
                if(nums[i] >= nums[i + 1])
                {
                    if(tempCis > cis)
                    {
                        cis = tempCis;
                    }
                    tempCis = 1;
                }
            }
            if (tempCis > cis)
            {
                cis = tempCis;
            }
            return cis;
        }
        //
        public int MaximumSwap(int num)
        {
            if (num < 0)
                return 0;

            int maxNum = 0;
            int tempNum;
            List<int> numToArray = new List<int>();
            //转换成数组
            while (num > 0)
            {
                numToArray.Add(num % 10);
                num = num / 10;
            }

            for (int i = numToArray.Count - 1; i > 0; i--)
            {
                tempNum = numToArray[i];
                int index = i;
                for (int j = 0; j < i; j++)
                {
                    if (tempNum < numToArray[j])
                    {
                        tempNum = numToArray[j];
                        index = j;
                    }
                }
                if (numToArray[index] != numToArray[i])
                {
                    var temp = numToArray[index];
                    numToArray[index] = numToArray[i];
                    numToArray[i] = temp;
                    
                    break;
                }
            }
            //转换为int
            for (int i = numToArray.Count - 1; i >= 0; i--)
            {
                maxNum = maxNum * 10 + numToArray[i];
            }
            return maxNum;
        }
        public int[] ConstructArray(int n, int k)
        {
            int[] longArray = new int[n];
            int[] shortArray = new int[k];
            for(int i = 1; i <= n; i++)
            {

            }
            return null ;
        }
        //非递减数组
        public bool CheckPossibility(int[] nums)
        {
            int count = 0;
            for(int i = 0; i < nums.Length -1; i++)
            {
                if (nums[i] > nums[i + 1])
                {
                    count++;
                }
                   
                if (count > 1)
                    return false;
            }
            return true;
        }
        //求连续数匹配 一个值的 次数
        public int SubarraySum(int[] nums, int k)
        {
            int times = 0;
            for(int i = 0;i< nums.Length; i++)
            {
                int sum = nums[i];
                if (sum == k)
                {
                    times++;
                }
                for (int j = i+1; j < nums.Length; j++)
                {
                    sum += nums[j];
                    if (sum == k)
                    {
                        times++;
                    }
                        
                }
            }
            return times;
        }
    }
}